package com.oracle.lingshangejia.fragment;

import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.oracle.lingshangejia.Constant;
import com.oracle.lingshangejia.R;
import com.oracle.lingshangejia.base.BaseFragment;
import com.oracle.lingshangejia.bean.RecordTakingBean;
import com.oracle.lingshangejia.utils.OkHttpUtils;
import com.oracle.lingshangejia.utils.SpUtils;

import java.util.HashMap;

/**
 * 接诊记录
 */
public class RecordtakingrecordsFragment extends BaseFragment{
    private int jmid;
    private int jzid;
    private String name;
    private TextView tv_record_name_sex;//患者姓名及性别
    private TextView tv_record_date;//问诊时间
    private TextView tv_record_yy;//会诊原因
    private TextView tv_record_doctorname;//医生姓名
    private TextView tv_record_datey;//诊断时间
    private TextView tv_record_zl;//客户资料
    private TextView tv_record_pgdoctor;//评估医生
    private TextView tv_record_pgdate;//评估下时间
    private TextView tv_record_pgcontent;//评估内容
    private RecordTakingBean mBean;

    @Override
    protected void initData() {
        getNetWork();
    }

    @Override
    protected void initView() {
        jmid=getArguments().getInt("jmid");
        jzid=getArguments().getInt("jzid");
        name=getArguments().getString("name");

    }

    @Override
    protected void onBindViewBefore(View view) {
        tv_record_name_sex=view.findViewById(R.id.tv_record_name_sex);
        tv_record_date=view.findViewById(R.id.tv_record_date);
        tv_record_yy=view.findViewById(R.id.tv_record_yy);
        tv_record_doctorname=view.findViewById(R.id.tv_record_doctorname);
        tv_record_datey=view.findViewById(R.id.tv_record_datey);
        tv_record_zl=view.findViewById(R.id.tv_record_zl);
        tv_record_pgdoctor=view.findViewById(R.id.tv_record_pgdoctor);
        tv_record_pgdate=view.findViewById(R.id.tv_record_pgdate);
        tv_record_pgcontent=view.findViewById(R.id.tv_record_pgcontent);
    }
    private void getNetWork() {
        int ysid= (int) SpUtils.get(getActivity(),"ysid",0);
        HashMap<Object, Object> map = new HashMap<>();
        map.put("ysid",ysid);
        map.put("jzid",jzid);
        map.put("jmid",jmid);
        OkHttpUtils.getNetWork(getActivity(), Constant.baseurl+"online/jzzz/jzjlDetail",map,handler);
    }
    private Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case 1:  //成功S
                    String s= (String) msg.obj;
                    Gson gson=new Gson();
                    mBean = gson.fromJson(s, RecordTakingBean.class);
                    if(mBean.getCode()==0){
                        tv_record_name_sex.setText("患者姓名："+name);
                        tv_record_yy.setText(mBean.getData().getJzzzgzl());
                        tv_record_zl.setText(mBean.getData().getJzzkgzl());
                        tv_record_pgdate.setText("诊断时间："+ mBean.getData().getJzrq());
                        tv_record_pgcontent.setText(mBean.getData().getPg());
                        tv_record_pgdoctor.setText("医生姓名："+ mBean.getData().getJzysName());
                    }else{
                        Toast.makeText(getActivity(), mBean.getMsg(),Toast.LENGTH_SHORT).show();
                    }
                    break;
                case 2: //连接上服务器，错误
                    String error= (String) msg.obj;
                    Toast.makeText(getActivity(),error,Toast.LENGTH_SHORT).show();
                    break;
                case 3:  //没有网络
                    Toast.makeText(getActivity(),"网络不可用",Toast.LENGTH_SHORT).show();
                    break;
                case 4: //没有连接上服务器
                    Toast.makeText(getActivity(),"连接服务器失败",Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    };

    public RecordTakingBean getRecordTakingBean(){

        return mBean;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_recordtakingrecords;
    }




}
